// 清华学堂 BiliBili 解析。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
const ll INF = 1e18;
int n, a[N], k;
vector<int> G[N];
ll dp[N][10][3], tmp[10][3], f[N][10];
/*
- *dp[u][k][0/1/2]：  0 表示为选入在路径外，1表示选入u作为端点,
2表示选入作为内部点, 限制为 *k*的答案。
*/
void dfs(int u, int fa) {
  for (int i = 0; i <= k; ++i) {
    dp[u][i][0] = dp[u][i][1] = dp[u][i][2] = -INF;
  }
  dp[u][0][0] = 0;
  dp[u][1][1] = a[u];

  for (int i = 0; i <= k; ++i)
    f[u][i] = max({dp[u][i][0], dp[u][i][1], dp[u][i][2]});

  for (auto v : G[u]) {
    if (v == fa)
      continue;
    dfs(v, u);
    for (int i = 0; i <= k; ++i)
      tmp[i][0] = tmp[i][1] = tmp[i][2] = -INF;

    for (int i = 0; i <= k; ++i) {
      for (int j = 0; j <= k; ++j) {
        tmp[i + j][0] = max(tmp[i + j][0], dp[u][i][0] + f[v][j]);
        tmp[i + j][1] = max(tmp[i + j][1], dp[u][i][1] + f[v][j]);
        tmp[i + j][2] = max(tmp[i + j][2], dp[u][i][2] + f[v][j]);
        if (i + j <= k)
          tmp[i + j][1] = max(tmp[i + j][1], dp[u][i][0] + a[u] + dp[v][j][1]);
        if (i && j && i + j - 1 <= k)
          tmp[i + j - 1][2] = max(tmp[i + j - 1][2], dp[u][i][1] + dp[v][j][1]);
      }
    }

    memcpy(dp[u], tmp, sizeof tmp);
    for (int i = 0; i <= k; ++i)
      f[u][i] = max({dp[u][i][0], dp[u][i][1], dp[u][i][2]});
  }
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }

  dfs(1, 0);
  ll ans = 0;
  for (int i = 0; i <= k; ++i)
    ans = max({ans, dp[1][i][0], dp[1][i][1], dp[1][i][2]});
  printf("%lld\n", ans);
  return 0;
}